package com.share.finance.risk.rules.web;

import com.alibaba.fastjson.JSONObject;
import com.share.common.common.Page;
import com.share.common.common.Result;
import com.share.finance.risk.rules.model.db.StrategyConf;
import com.share.finance.risk.rules.model.vo.StrategyConfAddOrUpdateReq;
import com.share.finance.risk.rules.model.vo.StrategyConfPageReq;
import com.share.finance.risk.rules.service.IStrategyConfService;
import com.share.finance.risk.rules.service.exe.TranslateService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author author
 * @since 2021-11-25
 */
@RestController
@RequestMapping("/strategy")
public class StrategyConfController {

    @Autowired
    private IStrategyConfService iStrategyService;

    @ApiOperation(value = "获取所有决策")
    @RequestMapping(value = "/pageList")
    public Result<Page<StrategyConf>> pageList(StrategyConfPageReq req) {
        Page<StrategyConf> page = iStrategyService.pageList(req);
        return Result.success(page);
    }

    @ApiOperation("新增")
    @RequestMapping("/add")
    public Result add(StrategyConfAddOrUpdateReq req) {
        StrategyConf record = new StrategyConf();
        BeanUtils.copyProperties(req, record);
        return Result.bool(iStrategyService.save(record));
    }

    @ApiOperation("修改")
    @RequestMapping("/update")
    public Result update(StrategyConfAddOrUpdateReq req) {
        if (req.getId() == null) {
            return Result.failure("参数异常!");
        }
        StrategyConf record = new StrategyConf();
        BeanUtils.copyProperties(req, record);
        return Result.bool(iStrategyService.updateById(record));
    }

    @ApiOperation("删除")
    @RequestMapping("/delete")
    public Result delete(Integer id) {
        return Result.bool(iStrategyService.removeById(id));
    }
}
